import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/common/js/http/'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false, //用户是否登录  
		token:null,
		userInfo: {}, //用户信息 
	},
	mutations: {
		setLoading(state, provider) {
			state.isPageLoading = provider
		},
		setToken(state, provider) { //改变登录状态
			state.hasLogin = true
			state.token = provider
			console.log(provider)
			console.log('providerproviderprovider')
			// uni.setStorageSync('token',provider)
			uni.setStorageSync('token', provider)
		},
		login(state, provider) { //改变登录状态
			state.hasLogin = true
			state.userInfo = provider
			uni.setStorage({ //将用户信息保存在本地  
				key: 'userInfo',
				data: provider
			})
		},
		logout(state) { //退出登录  
			state.hasLogin = false
			state.userInfo = {}
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'token'
			})
			uni.reLaunch({
				url: '/pages/login/login'
			});
		},
	}
})

export default store